Read all the way to the end of a file in one operation.
The following example reads all the way to the end of a file in one operation.
C# .NET |
public static String DoTest() { string strRet = ""; string path = @"c:\temp\MyTestReadToEnd.txt"; try { if (File.Exists(path)) { File.Delete(path); } StreamWriter sw = new StreamWriter(path); sw.WriteLine("This"); sw.WriteLine("is some text"); sw.WriteLine("to test"); sw.WriteLine("ReadToEnd method"); sw.Flush(); sw.Close(); StreamReader sr = new StreamReader(path); //This allows you to do one Read operation. strRet += (sr.ReadToEnd() + Environment.NewLine); sr.Close(); } catch (Exception e) { strRet += String.Format("The process failed: {0}", e.ToString()); } return strRet; } |
Blaze++ .NET |
static String DoTest() { String strRet = ""; String path = "c:\\temp\\MyTestReadToEnd.txt"; try { if (File::Exists(path)) { File::Delete(path); } StreamWriter sw(path); sw.WriteLine("This"); sw.WriteLine("is some text"); sw.WriteLine("to test"); sw.WriteLine("ReadToEnd method"); sw.Close(); StreamReader sr(path); //This allows you to do one Read operation. strRet += (sr.ReadToEnd() + Environment::NewLine); sr.Close(); } catch (Exception e) { strRet += String::Format("The process failed: {0}", e.ToString()); } return strRet; } |